package com.hanvon.faceid.client;

import com.google.gson.GsonBuilder;
import com.hanvon.faceid.sdk.FaceId;
import com.hanvon.faceid.sdk.FaceId_ErrorCode;
import junit.framework.Assert;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 公共方法
 */
public class AbstractBase {
	private static Log logger = LogFactory.getLog(AbstractBase.class);
	protected FaceId tcpClient;

	@Before
	public void connect() {
		String ip = "192.168.0.50";
		int port = 9922;
		tcpClient = new FaceId();
		FaceId_ErrorCode r = tcpClient.Connect(ip, port);
		Assert.assertEquals(FaceId_ErrorCode.Success, r);
	}

	@After
	public void destory() throws Exception {
		tcpClient.close();
	}

	protected String toJson(Object record) {
		return new GsonBuilder().create().toJson(record);
	}

	@Test
	public void GetDeviceInfo() throws Exception {
		// 读取考勤机配置、状态信息
		FaceId_DeviceInfo info = new FaceId_DeviceInfo();
		FaceId_ErrorCode r = FaceIdClient.GetDeviceInfo(tcpClient,info);
		Assert.assertEquals(FaceId_ErrorCode.Success, r);
		logger.info("deviceInfo=" + toJson(info));
	}
}